<?php
class Demand {
	const AFLOW_WAIT	= 0; //audit_flow,待审
	const AFLOW_PASS	= 1; //已审
	const AFLOW_FAIL	= 2; //失败

	const TYPE_SCHEME	= 0; //补库采购
	const TYPE_ADDIT	= 1; //专项采购
	const TYPE_URGENT	= 2; //紧急采购

	static function get($id){
		return Db::get(__CLASS__)->select()->where(array('id'=>$id))->getOne();
	}

	static function getDetail($id){
		return Db::get(__CLASS__)->select('t0.*,t1.name as user_name,t2.name as dept_name')
				->join(array('User','Dept'))->on(array('t0.user_id=t1.id','t0.dept_id=t2.id'))
				->where("t0.id={$id}")->getOne();
	}
	
	static function add($data){
		return Db::get(__CLASS__)->insert($data)->exec()
				? Db::get(__CLASS__)->insertId() : null;
	}

	static function count($where){
		return Db::get(__CLASS__)->count()->where($where)->getCol();
	}

	static function update($id, $data){
		return Db::get(__CLASS__)->update($data)->where(array('id'=>$id))->exec();
	}

	static function updateFlow($id, $audit_flow, $type=null){
		return Db::get(__CLASS__)->update(array('audit_flow'=>$audit_flow))
								->where(array('id'=>$id))->exec();
	}
}
?>
